package com.wanghaixin.controller;

import com.wanghaixin.dto.DataGridResult;
import com.wanghaixin.dto.QueryDTO;
import com.wanghaixin.pojo.CarParamType;
import com.wanghaixin.service.CarParamTypeService;
import com.wanghaixin.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @Auther: 王海新
 * @Date: 2020/11/2 09:42
 * @Description:
 */
@Controller
public class CarParamTypeController {

    @Autowired
    private CarParamTypeService carParamTypeService;

    /*********************************************************************************************************************
     * @Author:  王海新
     * @Date:  9:45  2020/11/2
     * @Version:  1.0.0
     * @Description:  分页查询
     */
    @RequestMapping("/sys/paramtype/list")
    @ResponseBody
    public DataGridResult findByPage(QueryDTO queryDTO){
        return carParamTypeService.findByPage(queryDTO);
    }

    /*********************************************************************************************************************
     * @Author:  王海新
     * @Date:  9:45  2020/11/2
     * @Version:  1.0.0
     * @Description:  删除
     */
@RequestMapping("/sys/paramtype/del")
    @ResponseBody
    public R delCarParamType(@RequestBody List<Integer> ids){
    for (Integer id : ids) carParamTypeService.delCarParam(id);
    return R.ok();
}

/*********************************************************************************************************************
 * @Author:  王海新
 * @Date:  9:48  2020/11/2
 * @Version:  1.0.0
 * @Description:  id查询
 */
@RequestMapping("/sys/paramtype/info/{id}")
@ResponseBody
public R findById(@PathVariable("id") Integer id){
    CarParamType byId = carParamTypeService.findById(id);
    return R.ok().put("paramtype",byId);
}

/*********************************************************************************************************************
 * @Author:  王海新
 * @Date:  9:50  2020/11/2
 * @Version:  1.0.0
 * @Description:  添加
 */
@RequestMapping("/sys/paramtype/save")
@ResponseBody
public R addCarParamType(@RequestBody CarParamType carParamType){
    int i = carParamTypeService.addCarParam(carParamType);
    return i>0 ? R.ok():R.error("添加失败");
}

/*********************************************************************************************************************
 * @Author:  王海新
 * @Date:  9:51  2020/11/2
 * @Version:  1.0.0
 * @Description:  修改
 */
@RequestMapping("/sys/paramtype/update")
    @ResponseBody
    public R upCarParamType(@RequestBody CarParamType carParamType){
    int i = carParamTypeService.upCarParam(carParamType);
    return i>0 ? R.ok(): R.error("修改失败");
}

}
